package com.gxa.controller.parking;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.common.utils.Result;
import com.gxa.entity.parking.VehicleBSelect;
import com.gxa.service.parking.VehicleBlistService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.gxa.entity.parking.VehicleBlist;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

import static com.gxa.common.utils.R.ok;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yjl
 * @since 2022-10-11 10:05:39
 */

@Api(tags = "车辆黑名单管理接口")
@RestController
@RequestMapping("/vehicle-blist")
public class VehicleBlistController {

    @Autowired
    private VehicleBlistService vehicleBlistService;

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("查询所有黑名单车辆")
    @PostMapping("/vehicleBList")
    public Result getBVehicle(@RequestBody VehicleBSelect vehicleBSelect) {
        PageHelper.startPage(vehicleBSelect.getPageNum(),vehicleBSelect.getPageSize());
        List<VehicleBlist> vehicleBlists = vehicleBlistService.selectList();
        PageInfo<VehicleBlist> vb = new PageInfo<>(vehicleBlists);
        return Result.success(vb);
    }


    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation(value = "条件查询")
    @PostMapping("/warn")
    @ResponseBody
        public Result selectByCondition(@RequestBody VehicleBSelect vehicleBSelect){
            PageHelper.startPage(vehicleBSelect.getPageNum(),vehicleBSelect.getPageSize());
            List<VehicleBlist> vs = this.vehicleBlistService.selectByCondition(vehicleBSelect);
            PageInfo<VehicleBlist> ve = new PageInfo<>(vs);
            return  Result.success(ve);
        }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation(value = "更新黑名单车辆")
    @PutMapping("/updateBVehicle")
    public String updateBVehicle(@RequestBody VehicleBlist vehicleBlist) {
        vehicleBlistService.updateById(vehicleBlist);
         return "a";

    }
    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation(value = "添加黑名单车辆")
    @PostMapping("/addBVehicle/{VehicleBlist}")
    public String addBVehicle(@RequestBody VehicleBlist vehicleBlist) {
            if(vehicleBlistService.addVehicle(vehicleBlist)){
                return "添加成功";
            }else{
                return "添加失败";
            }
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("删除黑名单记录")
    @DeleteMapping("/del/{id}")
    public String delById(@PathVariable("id") Integer id) {
        if(vehicleBlistService.deleteById(id)){
            return "删除成功";
        }else{
            return "删除失败";
        }
    }
}